@namespace NewLife.CubeBlazor.Razor.Shared.Layouts
@inherits CubeComponentBase

<MDialog @bind-Value="Visible"
         Persistent
         MaxWidth="320">
    <ChildContent>
        <MCard>
            <MCardTitle>
                @T("UserException")
            </MCardTitle>
            <MCardText>
                @T("UserExceptionMsg")
            </MCardText>
            <MCardActions>
                <MSpacer></MSpacer>
                <MButton Color="red darken-1" Text OnClick="Logout">
                    @T("Confirm")
                </MButton>
            </MCardActions>
        </MCard>
    </ChildContent>
</MDialog>

@code {
    [Parameter]
    public bool Visible { get; set; }

    [Parameter]
    public EventCallback<bool> VisibleChanged { get; set; }

    private async Task Logout()
    {
        await Hiden();
        NavigationManager.NavigateTo($"/Account/Logout?redirectToLogin={true}", true);
    }

    private async Task Hiden()
    {
        if (VisibleChanged.HasDelegate)
        {
            await VisibleChanged.InvokeAsync(false);
        }
        else
        {
            Visible = false;
        }
    }
}
